package com.springinaction.ch03.PlaceholderSpel;

import org.junit.Rule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.SystemOutRule;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static org.junit.Assert.*;

/**
 * https://blog.csdn.net/Cool_Coding/article/details/90617687 加载properties的几种方式
 *
 * 1 直接使用 @PropertySource(properties地址)注解 取 ${a.title}
 * 2 使用PropertyPlaceholderConfigurerl类 locations参数list加载   取 ${a.title}
 * 3 使用PropertySourcesPlaceholderConfigurer  locations参数list加载    取 ${a.title} 类似PropertyPlaceholderConfigurerl
 * 4 为简化PropertyPlaceholderConfigurer的使用，Spring提供了<context:property-placeholder/>元素,启用它后，开发者便不用配置PropertyPlaceholderConfigurer对象了
 * 5 util:properties  <util:properties id="id" location=""/> 读取方式  id['a.title']
 * 6 PropertiesFactoryBean 与5类似
 * spel不懂.....
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = PropertyConfig.class)
//@ContextConfiguration("classpath:com/springinaction/ch03/PlaceholderSpel/propertiesConfig.xml")
public class PropertyTest {

    @Rule
    public final SystemOutRule log=new SystemOutRule().enableLog();

    @Autowired
    private BlankDisc blankDisc;  /*记得改上面的包*/

    @Test
    public void blankDiscPlay(){
        blankDisc.play();
        //System.out.println(env.getProperty("title"));
        assertEquals("Playing Sgt. Pepper's Lonely Hearts Club Band by The Beatles\r\n",log.getLog());


    }

}
